/**
 * 通过提交表单下载
 * @param {*} action 下载地址
 * @param {*} method 下载方法 get | post
 * @param {*} params 参数对象
 */
 let iframeElement = null;

 function formDownload({ action = '', method = 'get', params = {} }) {
 
   const entries = Object.entries(params);
   const formElement = document.createElement('form');
 
   if (!iframeElement) {
     iframeElement = document.createElement('iframe');
     iframeElement.name = 'submitHere';
     iframeElement.id = 'submitHere';
     iframeElement.style.cssText = 'display: none';
     document.body.appendChild(iframeElement);
   }
   formElement.action = action;
   formElement.method = method;
   formElement.target = 'submitHere';
   for (let [key, value] of entries) {
     let fieldElement = document.createElement('input');
 
     fieldElement.value = value;
     fieldElement.name = key;
     formElement.appendChild(fieldElement);
   }
   document.body.appendChild(formElement);
   formElement.submit();
   document.body.removeChild(formElement);
 }
 
 export default {
   post: (action, params) => {
     formDownload({
       action,
       method: 'post',
       params
     });
   },
   get: (action, params) => {
     formDownload({
       action,
       method: 'get',
       params
     });
   }
 };
 